home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_355 / tracksalve / source / _main.a next >
Text File  |  1992-05-06  |  3KB  |  93 lines

  1.  
  2.         INCLUDE "call.i"
  3.  
  4. EOL        equ    $0a        CLI command activator
  5.  
  6. *-------------------------------------------------------*
  7. *
  8. *  - __main -
  9. *
  10. *  Function:    Convert commandline to argv and argc, then call main() with them
  11. *
  12. *  Input:    4(a7).l Pointer to commandline
  13. *
  14. *  Output:    d0.l    Return value (as can be used in script files)
  15. *
  16. *
  17.  
  18.         csect    text,0,0,1,2
  19.  
  20.         Func    __main
  21.         movem.l d2/d3/a2,-(a7)
  22.  
  23. *--    Insert terminators, get pointers, find argc
  24.  
  25.         move.l    a7,a2            Keep stackpointer
  26.         move.l    16(a7),a0        Get begin
  27.         lea.l    0(a7),a1        Remember first argv for reverse action
  28.         moveq.l #0,d3            Argc (program name)
  29.  
  30. SearchNextSpace move.b    (a0),d0            Search *argv
  31.         cmp.b    #' ',d0            Spaces are delimiters
  32.         bhi.s    ArgvFound        Any printable but SP causes an *argv
  33.         bcs.s    FinalTerm        Any control causes a leave loop
  34. KillSpace    clr.b    (a0)+            No spaces allowed
  35.         bra.s    SearchNextSpace
  36. ArgvFound    cmp.b    #'"',d0            Entry embedded spaces?
  37.         beq.s    SpecialFound        Yes, special search action
  38.         move.l    a0,-(a7)        No, normal, push a *argv
  39.         addq.l    #1,d3            ++Argc
  40. SearchSpace    cmp.b    #' ',(a0)        Now search for end
  41.         beq.s    KillSpace        End found, search next *argv
  42.         bcs.s    FinalTerm        Very end found; leave
  43.         addq.l    #1,a0            Still inside argument,
  44.         bra.s    SearchSpace        So keep searching for delimiter
  45. SpecialFound    addq.l    #1,a0            Skip special entry code char
  46.         move.l    a0,-(a7)        Push a *argv
  47.         addq.l    #1,d3            ++Argc
  48. SearchSpecial    move.b    (a0),d0            Only '"' and '\0' are delimiters (EOL?)
  49.         beq.s    FinalTerm        Very end found; leave
  50.         cmp.b    #'"',d0            Special delimiter?
  51.         beq.s    KillSpace        Yes, act like space found
  52.         cmp.b    #EOL,d0            @ We look for EOL too
  53.         beq.s    FinalTerm        @ And leave on meeting it
  54.         addq.l    #1,a0            No, still inside argument,
  55.         bra.s    SearchSpecial        So keep searching for delimiter
  56. FinalTerm    clr.b    (a0)            Now, here is my story:
  57.  
  58. * If the command line does not contain any embedded space arguments,
  59. * FinalTerm deletes the closing control, normally a LF. However, you are
  60. * allowed to embed all controls but '\0' in embedded space arguments. If
  61. * you do not close this argument with '"', but instead gives an EOL, this
  62. * EOL takes part of this argument. In this version, we leave the loop on
  63. * finding it. (@)
  64.  
  65. *--    The argv-array is in reversed order, so do something about it
  66.  
  67.         move.l    a7,a0            Get begin, end is already in a1
  68.         move.l    d3,d2            Get number of pointers
  69.         lsr.l    #1,d2            Argc/2 we exchange two at a time
  70.         bra.s    ExchPointers1
  71. ExchPointers0    move.l    -(a1),d0
  72.         move.l    (a0),d1
  73.         move.l    d0,(a0)+
  74.         move.l    d1,(a1)
  75. ExchPointers1    dbra    d2,ExchPointers0
  76.  
  77. *--    For some reasons its nice to have a long aligned stackpointer.
  78.  
  79.         move.l    a7,d1            Argv
  80.         move.l    a7,d0            Prepare for long line up
  81.         lsr.l    #2,d0            We look for a carry
  82.         bcc.s    LongAlined        Already long
  83.         subq.l    #2,a7            Make a7 long aligned
  84. LongAlined    move.l    d1,-(a7)        Push *argv[]
  85.         move.l    d3,-(a7)        Push argc
  86.         Call    _main            main()
  87.         move.l    a2,a7            Restore stackpointer
  88.         movem.l (a7)+,d2/d3/a2
  89.         rts
  90.  
  91.         END
  92.  
  93.